home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / dfirst.zip / DFIRST.C next >
Text File  |  1986-10-14  |  3KB  |  163 lines

  1. /* find files from wildcards, for MicroSoft C v4.0 */
  2.  
  3. /* ------------------------------------------------------------ */
  4. /*   copyright 1986:                        */
  5. /*            Nourse Gregg & Browne, Inc.        */
  6. /*            1 Horizon Road. #612            */
  7. /*            Fort Lee, NJ 07024            */
  8. /*                                */
  9. /* ------------------------------------------------------------ */
  10.  
  11.  
  12. /* ----------------------------------------------------------------------*
  13.     This pair of routines will do a wildcard search
  14.  
  15.     you must call dfirst() once to supply the search pattern
  16.     and get back the first file that matches that pattern.
  17.  
  18.     then, call dnext() to get the next file in the list.
  19.  
  20.     both dfirst() and dnext() return zero if a file has been found,
  21.         non-zero otherwise.
  22.  
  23.  
  24.     The calling parameters are as follows:
  25.  
  26.  
  27.     dfirst(pattern,attr,file_name,file_date,file_time,file_size);
  28.  
  29.     dnext(file_name,file_date,file_time,file_size);
  30.  
  31.  
  32.      Where:
  33.  
  34.     char *pattern;     (wild card pattern. eg. "*.c" )
  35.     int   attr;     (the file attribute qualifier )
  36.     char *file_name; (output: the name of found file (13 bytes min.) )
  37.     int  *file_date; (output: the file's date (directory format) )
  38.     int  *file_time; (output: the file's time )
  39.     long *file_size; (output: the file's size in bytes )
  40.  
  41.  
  42.  
  43. *----------------------------------------------------------------- */
  44.  
  45. #include <dos.h>
  46. #include <stdlib.h>
  47.  
  48. #define SET_DTA 0x1A
  49. #define GET_DTA 0x2F
  50. #define FIND_FIRST 0x4E
  51. #define FIND_NEXT 0x4F
  52.  
  53.  
  54.  
  55.     struct dta_struct {
  56.     char dummy[21];
  57.     char attr;
  58.     int time;
  59.     int date;
  60.     int low_size;
  61.     int hi_size;
  62.     char name[13];
  63.     char dummy2[14];
  64.     };
  65.  
  66. static struct dta_struct dta;
  67.  
  68. dfirst (fmask,fattr,fname,fdate,ftime,fsize)
  69. char *fmask;
  70. int   fattr;
  71. char *fname;
  72. int  *fdate;
  73. int  *ftime;
  74. long *fsize;
  75.     {
  76.     union REGS  inregs,outregs;
  77.     struct SREGS segregs;
  78.     int old_dta_seg;
  79.     int old_dta_offset;
  80.     int rc;
  81.     long l;
  82.  
  83.     segread(&segregs);
  84.  
  85.     inregs.h.ah=GET_DTA;
  86.     intdosx(&inregs,&outregs,&segregs);
  87.     old_dta_seg=segregs.es;
  88.     old_dta_offset=outregs.x.bx;
  89.  
  90.     inregs.h.ah=SET_DTA;
  91.     inregs.x.dx=&dta;
  92.     intdos(&inregs,&outregs);
  93.  
  94.     inregs.h.ah=FIND_FIRST;
  95.     inregs.x.dx=fmask;
  96.     inregs.x.cx=fattr;
  97.     intdos(&inregs,&outregs);
  98.     rc=(outregs.x.cflag & 0x0001);
  99.  
  100.     inregs.h.ah=SET_DTA;
  101.     inregs.x.dx=old_dta_offset;
  102.     segregs.ds=old_dta_seg;
  103.     intdosx(&inregs,&outregs,&segregs);
  104.  
  105.     if (rc==0)
  106.         {
  107.         *ftime=dta.time;
  108.         *fdate=dta.date;
  109.         l=dta.hi_size;
  110.         l=l<<16;
  111.         l=l+dta.low_size;
  112.         *fsize=l;
  113.         strncpy(fname,dta.name,13);
  114.         }
  115.     return(rc);
  116.     }
  117.  
  118. dnext (fname,fdate,ftime,fsize)
  119. char *fname;
  120. int  *fdate;
  121. int  *ftime;
  122. long *fsize;
  123.     {
  124.     union REGS  inregs,outregs;
  125.     struct SREGS segregs;
  126.     int old_dta_seg;
  127.     int old_dta_offset;
  128.     int rc;
  129.     long l;
  130.  
  131.     segread(&segregs);
  132.  
  133.     inregs.h.ah=GET_DTA;
  134.     intdosx(&inregs,&outregs,&segregs);
  135.     old_dta_seg=segregs.es;
  136.     old_dta_offset=outregs.x.bx;
  137.  
  138.     inregs.h.ah=SET_DTA;
  139.     inregs.x.dx=&dta;
  140.     intdos(&inregs,&outregs);
  141.  
  142.     inregs.h.ah=FIND_NEXT;
  143.     intdos(&inregs,&outregs);
  144.     rc=(outregs.x.cflag & 0x0001);
  145.  
  146.     inregs.h.ah=SET_DTA;
  147.     inregs.x.dx=old_dta_offset;
  148.     segregs.ds=old_dta_seg;
  149.     intdosx(&inregs,&outregs,&segregs);
  150.  
  151.     if (rc==0)
  152.         {
  153.         *ftime=dta.time;
  154.         *fdate=dta.date;
  155.         l=dta.hi_size;
  156.         l=l<<16;
  157.         l=l+dta.low_size;
  158.         *fsize=l;
  159.         strncpy(fname,dta.name,13);
  160.         }
  161.     return(rc);
  162.     }
  163.